package com.parking.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.parking.common.pagination.Page;
import com.parking.common.pagination.PageUtil;
import com.parking.dao.IFreeParkingDao;
import com.parking.entity.FreeParking;
import com.parking.service.IFreeParkingService;

@Service("freeParkingService")
public class FreeParkingServiceImpl implements IFreeParkingService{
	
private static Logger logger = Logger.getLogger(FreeParkingServiceImpl.class);
	
	@Autowired
    @Qualifier("freeParkingDao")
	private IFreeParkingDao freeParkingDao;

	@Override
	public Page<FreeParking> findByKeywordAndAreacode(String keyword,
			int areacode, int pageSize, int pageNum) {
		List<FreeParking> freeParkings = freeParkingDao.findByKeywordAndAreacode(keyword, areacode, pageSize, pageNum);
		Long count = freeParkingDao.countByKeywordAndAreacode(keyword, areacode);
		Long totalPages = PageUtil.getTotalPages(count, pageSize);
		return PageUtil.getPage(pageNum, pageSize, freeParkings, count, totalPages);
	}

	@Override
	public List<FreeParking> findByKeywordAndAreacode(String keyword, int areacode) {
		return freeParkingDao.findByKeywordAndAreacode(keyword, areacode);
	}

	@Override
	public long countByKeywordAndAreacode(String keyword, int areacode) {
		return freeParkingDao.countByKeywordAndAreacode(keyword, areacode);
	}

	@Override
	public Page<FreeParking> findByHotKey(int hotKey, int pageSize, int pageNum) {
		List<FreeParking> freeParkings = freeParkingDao.findByHotKey(hotKey, pageSize, pageNum);
		Long count = freeParkingDao.countByHotKey(hotKey);
		Long totalPages = PageUtil.getTotalPages(count, pageSize);
		return PageUtil.getPage(pageNum, pageSize, freeParkings, count, totalPages);
	}

	@Override
	public long countByHotKey(int hotKey) {
		return freeParkingDao.countByHotKey(hotKey);
	}

}
